import openscad as o


o.fragments=150

###################################################################################################

# original housing
origWall  = 1
origDepth = 23
# housing inner dimensions
Height = 39.6
Length = 71.9
Depth  = 42
Wall   = 2
# opening for fan
fanDia = 30
# opening for connections
conLength = 20
conDepth  = 5
conHeigth = conLength
# diameter of screw for connections
conScrewDia = 4
conScrewGap = 1.5  # gap between screws

###################################################################################################

# outer shell
o.box( Length+2*Wall, Depth+2*Wall, Height+2*Wall )
o.color("green", 0.1)
outerShell = o.result()
# inner shell
o.box( Length, Depth+2*Wall, Height )
o.color("red", 1)
o.translate( Wall, -Wall, Wall )
innerShell = o.result()

# hollow out outer shell
o.difference([outerShell, innerShell])
Shell=o.result()

# cylinder for cutting out fan opening
o.cylinder(fanDia, fanDia);
fanOpening = o.result()
# cut out cross from cylinder
o.box(fanDia+2*Wall, Wall, fanDia+2*Wall)
o.translate(-(fanDia+2*Wall)/2, -0.5*Wall, -Wall)
Cross01=o.result()
#
o.box(Wall, fanDia+2*Wall, fanDia+2*Wall)
o.translate(-0.5*Wall, -(fanDia+2*Wall)/2, -Wall)
Cross02=o.result()
#
o.union([Cross01, Cross02])
Cross = o.result()

# cut out fanopening from shell
o.difference([fanOpening, Cross])
o.rotate(90,45,0)
o.translate((Length+2*Wall)/2, Depth+fanDia/2, Height-fanDia/2+Wall-origWall)
o.difference([Shell, o.result()])
Shell=o.result()

# cut out opening for connection ports
o.box(conLength, conDepth, conHeigth)
o.translate((Length+2*Wall)/2-conLength/2, origDepth-conDepth, -conHeigth/2)
o.difference([Shell, o.result()])
Shell=o.result()

# cut out holes for 4 connection screws on backside
for i in range (4):
    o.cylinder(conScrewDia, 4*Wall)
    o.rotate(90,0,0)
    o.translate( (Length+2*Wall)/2-1.5*conScrewGap-1.5*conScrewDia + i*(conScrewGap+conScrewDia), Depth+4*Wall, conScrewDia/2+Wall+origWall)
    o.difference([Shell, o.result()])
    Shell=o.result()

# create horizontal air venting slits
for i in range (5):
    o.box(Length+4*Wall, Wall, Height-0.5*Wall)
    o.translate(-Wall, origDepth + i*(2*Wall), (Height+2*Wall)/2-(Height-0.5*Wall)/2 )
    o.difference([Shell, o.result()])
    Shell=o.result()

# create labels
labels=["Vout+","Vout-","Vin-","Vin+"]
index=0
for label in labels:
    o.text(label, size=2, height=2, valign="center")
    o.color("red",1)
    o.rotate(0,180,90)
    o.translate((Length+2*Wall)/2+conLength/2-conScrewGap-index*(conScrewGap+conScrewDia), origDepth-conDepth-origWall, 1)
    o.difference([Shell, o.result()])
    Shell=o.result()
    index=index+1


# ~ o.rotate(0,180,90)
# ~ o.translate((Length+2*Wall)/2+conLength/2-conScrewGap, origDepth-conDepth-origWall, 1)
# ~ o.union([Shell, o.result()])
# ~ Shell=o.result()
# ~ o.text("OUT-", size=2, height=2)
# ~ o.rotate(0,180,90)
# ~ o.translate((Length+2*Wall)/2+conLength/2-conScrewGap-, origDepth-conDepth-origWall, 1)
# ~ o.union([Shell, o.result()])
# ~ Shell=o.result()




# ~ o.output([o.result(), Shell])
# ~ o.output(o.result())
o.output(Shell)
